tmpdir="@KEDR_TEST_PREFIX_TEMP_SESSION@/kedr_fsim_final_template_reuse_fpoint"
payload_fsim="@kmodule_name@.ko"

test_function()
{
	# Whether all needed fault simulation points are created
	if ! test -d "${fault_simulation_points_dir}/__kmalloc"; then
		printf "Fault simulation point '__kmalloc' is not created.\n"
		return 1
	fi

	if ! test -d "${fault_simulation_points_dir}/krealloc"; then
		printf "Fault simulation point 'krealloc' is not created.\n"
		return 1
	fi
	# Whether __krealloc fault simulation point is not created
	if test -d "${fault_simulation_points_dir}/__krealloc"; then
		printf "Fault simulation point '__kmalloc' is created but shouldn't.\n"
		return 1
	fi


	# Whether fault simulation points have correct format strings
	format_string=`cat "${fault_simulation_points_dir}/__kmalloc/format_string"`
	if test "${format_string}" != "int"; then
		printf "Fault simulation point '__kmalloc' has format string '%s', but should has '%s'.\n" "${format_string}" "int"
		return 1
	fi

	format_string=`cat "${fault_simulation_points_dir}/krealloc/format_string"`
	if test "${format_string}" != ""; then
		printf "Fault simulation point 'krealloc' has format string '%s', but should has '%s'.\n" "${format_string}" ""
		return 1
	fi


	# Load indicator for __kmalloc fault simulation point
	if ! echo "${indicator_greater_than_name}" "10" > "${fault_simulation_points_dir}/__kmalloc/current_indicator"; then
		printf "Fail to set indicator for fault simulation point '__kmalloc'.\n"
		return 1
	fi

	# Verify that parameters are passed correctly to the indicator
	# for __kmalloc fault simulation point.
	if ! trigger_function "__kmalloc" "10"; then
		printf "Execution of __kmalloc should succeed, but it doesn't.\n"
		return 1
	fi

	if trigger_function "__kmalloc" "11"; then
		printf "Execution of __kmalloc should fail(because of indicator), but it doesn't.\n"
		return 1
	fi

	# Verify that reusing of fault simulation point is work(__krealloc)
	if ! trigger_function "__krealloc" "10"; then
		printf "Execution of __krealloc should succeed, but it doesn't.\n"
		return 1
	fi

	if trigger_function "__krealloc" "11"; then
		printf "Execution of __krealloc should fail(because of indicator), but it doesn't.\n"
		return 1
	fi


	# Verify that "normal" execution of the krealloc is as expected.
	if ! trigger_function "krealloc" "10"; then
		printf "Normal execution of krealloc fails, but should not.\n"
		return 1
	fi

	# Verify that "fault" execution of the krealloc is as expected.
	if ! echo "${indicator_constant_name}" "1" > "${fault_simulation_points_dir}/krealloc/current_indicator"; then
		printf "Fail to set indicator for fault simulation point 'krealloc'.\n"
		return 1
	fi

	if trigger_function "krealloc" "10"; then
		printf "Execution of krealloc should fail(because of indicator), but it doesn't.\n"
		return 1
	fi
}